<%@ page contentType="text/html; charset=UTF-8" language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> 
<%@ include file="/WEB-INF/jsp/common/taglibs.jsp" %>

<script src="${appPath }/resource/js/validate_forminp.js" type="text/javascript" ></script>

<script>

$(function() {
	$( "#format" ).buttonset();	
	$("#isBasicFormPriority").bind("click", function() {
		changeBasicFormPriority(true);
	});
});

function pageTo(n){	
	$('#nowPage').val(n);
	$.post("${appPath}/form/page/own/list.htm",$('#PageForm').serialize(),function(data){
		$("#querylist").html(data);
		$("#ChgRowPerPageLoadingImg").hide();
	});
}

function chgRowPerPage(n){
	$("#ChgRowPerPageLoadingImg").show();
	$('#rowsPerPage').val(n);
	pageTo(1);
}

function _submit(istemp){
	var seq_no = $("#seq_no").val();	
	if(istemp == 0 || validate()){
		$("#flow").val(istemp);
		var msg = (istemp == 0) ? "表單暫存" : "表單編輯";	
		$.post("${appPath}/form/edit.htm",$('#AgricultureAndFoodForm').serialize(),function(data){
			if(data){			
				var _clazz_li = "";
				$('.clazz').each(function(){			
					if($(this).prop("checked")){
						_clazz_li += "<li>" + $(this).attr("v") + "</li>";
					}
				});			
				
				var _clazz = "<ul>" + _clazz_li + "</ul>";
				var _title_o = $("#title_o").val();
				var _title_c = $("#title_c").val();
				var _author  = $("#author").val();
				var _affiliation = $("#affiliation").val();
				var _publisher = $("#publisher").val();
				var _journal = $("#journal").val();
				var _vol_page = $("#vol_page").val();
				var _keyword_o = $("#keyword_o").val();	
				var _url  = $("#url").val();
				var _abstract_c = $("#abstract_c").val();	
				var _abstract_o = $("#abstract_o").val();	
				var _year = $('#year option:selected').text();
				var _language = $('#language option:selected').text();
				var _doc_type = $('#doc_type option:selected').text();
				var _analyzed = $('.analyzed:checked').val() == "true" ? "有" : "無";	
				var _countries = $('#countries_name_ch').val();	
				var _plants_ch = $('#plants_name_ch').val();			
				_plants_ch = replaceAll(_plants_ch,",","、").substring(0,_plants_ch.length-1);
				_countries = replaceAll(_countries,",","、").substring(0,_countries.length-1);			
				var _literature = $('#literature option:selected').text();				
				if($('#literature option:selected').val() == 4){
					_literature += " : " +  $("#literature_desc").val();	
				}
				
				
				$("#show_plants").html(_plants_ch);	
				$("#show_countries").html(_countries);				
				$("#show_title_o").html(_title_o);
				$("#show_title_c").html(_title_c);
				$("#show_author").html(_author);
				$("#show_affiliation").html(_affiliation);
				$("#show_publisher").html(_publisher);
				$("#show_journal").html(_journal);
				$("#show_vol_page").html(_vol_page);
				$("#show_keyword_o").html(_keyword_o);
				$("#show_url").html(_url);
				$("#show_abstract_c").html(_abstract_c);	
				$("#show_abstract_o").html(_abstract_o);
				$("#show_year").html($('#year option:selected').val() == '0' ? '' : _year);
				$("#show_language").html($('#language option:selected').val() == '0' ? '' : _language);
				$("#show_doc_type").html($('#doc_type option:selected').val() == '0' ? '' : _doc_type);	
				$("#show_clazz").html(_clazz);
				$("#show_literature").html(_literature);	
				$("#show_analyzed").html(_analyzed);
				$(".editField").hide();
				$(".showField").show();
				$("#Span_Rec_No").html(data);				
				$("#LIST_TITLE_O_" + seq_no).html(_title_o);
				$("#LIST_AUTHOR_" + seq_no).html(_author);
				$("#LIST_YEAR_" + seq_no).html($('#year option:selected').val() == '0' ? '' : _year);				
				if(istemp == 1)				
					$("#LIST_FLOW_" + seq_no).css("color","blue").html("完成");				
				showMessage(msg + "成功",1);
			}
			else{
				showMessage(msg + "失敗",2);
			}
		});
	}else{
		showMessage("尚有欄位未完成",2);
	}
}

function queryForType(obj){	
	var qt1 = $("#queryType").val();
	var qt = $("#queryType").val();
	
	if(obj.checked){				
		if(obj.id == "check1"){
			$("label").each(function(){
				if($(this).attr("for") != 'check1'){
					var _id = $(this).attr("for");
					$("#" + _id).prop("checked",false);
					$(this).removeClass("ui-state-active");							
				}
			});
			qt = "9,";
		}else{
			qt = replaceAll(qt,"9,","");
			qt += obj.value + ",";
			
			$("label").each(function(){
				if($(this).attr("for") == 'check1'){
					var _id = $(this).attr("for");
					$("#" + _id).prop("checked",false);
					$(this).removeClass("ui-state-active");					
				}
			});
		}		
	}else{
		qt = replaceAll(qt,obj.value + ",","");
	}
	$("#queryType").val(qt);		
	
	
	var falseCount = 0;
	var trueCount = 0;
	
	$("#format :checkbox").each(function(){
		if($(this).prop("checked") == false)
			falseCount++;
		else{
			var _v = $(this).val();
			if(_v == 0 || _v == 1 || _v == 2)
				trueCount++;
		}			
	});
	
	if(falseCount == 4 || trueCount == 3){
		$("label").each(function(){
			var _id = $(this).attr("for");			
			if($(this).attr("for") == 'check1'){
				$("#" + _id).prop("checked",false);
				$(this).addClass("ui-state-active");
				$("#queryType").val("9,");	
			}else{
				$("#" + _id).prop("checked",false);
				$(this).removeClass("ui-state-active");	
			}
		});
	}
	
	if(qt1 != $("#queryType").val()){
		$("#requery").val("true");	
		pageTo(1);
	}
}

function showLiteratureDesc(obj){
	$("#AgricultureAndFoodForm input[name=literature_desc]").prop("disabled",!obj.checked);	
	document.getElementById("AgricultureAndFoodForm").elements["literature_desc"].focus();
}

function changeBasicFormPriority(n){	
	var img = n ? "1321928731_unchecked.gif" : "1321928729_checkbox.gif";
	var span = "<img src='${appPath }/resource/image/" + img + "' border='0' width=14 height13 />&nbsp;基本資料表單優先";	
	$("#isBasicFormPriority").html(span);	
	$("#isBasicFormPriority").unbind("click").bind("click", function() {
		changeBasicFormPriority(!n);
	});
	$("#PageForm input[name=basicFormPriority]").val(!n);
	$("#thisFormType").val(n == true ? "2" : "1");
}

</script>

<div id="page">
	<div id="page-bgtop">
		<div id="page-bgbtm">
			<div id="content">
				<div class="post">
					<%-- 
					<h2 class="title inner">我的表單<span id="loading_1" style="padding-left:20px;display:none;"><img src="${appPath }/resource/image/ajax-loader.gif" /></span></h2>
					
					<div style="clear: both;">&nbsp;</div> 
					--%>					
					<div class="entry">
						<c:if test="${fn:length(PageForm.obj) == 0}" >							
							<div style="padding-top:5px;">
								<table style="border: 1px solid #C0C0C0;">	
									<tr>
										<td>
											<div style="padding:20px;font-size: 16px;font-weight: 300;letter-spacing: 4px;">
												<img src="${appPath }/resource/image/1320894006_Problem.png" style="vertical-align:middle;"/>
												<span style="color: #3B5998;">目前尚無表單資料</span>
											</div>
										</td>
									</tr>
								</table>
							</div>						
						</c:if>
					
						<c:if test="${fn:length(PageForm.obj) != 0}" >								
							<table style="width:800px;" id="DIS_ROWPERPAGE">	
								<tr>
									<td style="text-align: left">							
										<!-- 狀態： 
										
										<input type="checkbox" value="9" checked="checked" onclick="queryForType(this);" /> 全部
										<input type="checkbox" value="0" onclick="queryForType(this);" /> 暫存中
										<input type="checkbox" value="1" onclick="queryForType(this);" /> 輸入完成
										<input type="checkbox" value="2" onclick="queryForType(this);" /> 研析完成
										
										<table style="width:300px;color: black;">	
											<tr>
												<td style="width:25%;text-align: center;cursor: pointer;border: 2px solid black;">全部</td>
												<td style="width:25%;text-align: center;cursor: pointer;border: 2px solid black;">暫存中</td>
												<td style="width:25%;text-align: center;cursor: pointer;border: 2px solid black;">輸入完成</td>
												<td style="width:25%;text-align: center;cursor: pointer;border: 2px solid black;">研析完成</td>
											</tr>
										</table>
										
										<span style="color: #272727;letter-spacing: 2px;">
											<span id="queryType_9" style="background-color: #6AFF00;border: 2px solid #272727;padding: 6px;" onclick="queryForType(this);">全部</span>
											<span id="queryType_0" class="queryType" style="cursor: pointer;border: 2px solid #272727;padding: 6px;" onclick="queryForType(this);">暫存中</span>
											<span id="queryType_1" class="queryType" style="cursor: pointer;border: 2px solid #272727;padding: 6px;" onclick="queryForType(this);">輸入完成</span>
											<span id="queryType_2" class="queryType" style="cursor: pointer;border: 2px solid #272727;padding: 6px;" onclick="queryForType(this);">研析完成</span>
										</span>
										-->
										
										<span id="format" style="margin-top: 2em;font-size: 10px;"> 
											<input type="checkbox" id="check1" checked="checked" value="9" onclick="queryForType(this);"/><label for="check1">全部</label> 
											<input type="checkbox" id="check2" class="_check" value="0" onclick="queryForType(this);"/><label for="check2">暫存中</label> 
											<input type="checkbox" id="check3" class="_check" value="1" onclick="queryForType(this);"/><label for="check3">輸入完成</label> 
											<input type="checkbox" id="check4" class="_check" value="2" onclick="queryForType(this);"/><label for="check4">研析完成</label> 
										</span>
										<span id="isBasicFormPriority" style="letter-spacing:1px;padding-left: 15px;cursor: pointer;">
											<img src="${appPath }/resource/image/1321928729_checkbox.gif" border="0" />&nbsp;基本資料表單優先
										</span>
										
										<!-- 
										<select id="type" onchange="" style="width:150px" class="bar_1">
											<option value="9">全部</option>
											<option value="0">暫存中</option>
											<option value="1">輸入完成</option>
											<option value="2">研析完成</option>
										</select>
										-->
										
									</td>
									<td style="text-align: right" valign="bottom">
										<span id="ChgRowPerPageLoadingImg" style="display:none">
											<img src="${appPath }/resource/image/ajax-loader.gif" />
										</span>
										<select class="bar_1" style="width:50px;" onchange="chgRowPerPage(this.value);">
											<option value="10" <c:if test="${ROWPERPAGE == 10 }">selected</c:if>>10</option>
											<option value="20" <c:if test="${ROWPERPAGE == 20 }">selected</c:if>>20</option>
											<option value="50" <c:if test="${ROWPERPAGE == 50 }">selected</c:if>>50</option>
											<option value="100" <c:if test="${ROWPERPAGE == 100 }">selected</c:if>>100</option>
										</select>
									</td>
								</tr>
							</table>	
							<div id="querylist"><%@ include file="list.jsp" %></div>	
							<div id="view"></div>						
						</c:if>
						
						
					</div>					
				</div>
				<div style="clear: both;">&nbsp;</div>
			</div>
			<!-- end #content -->			
			<%@ include file="/WEB-INF/jsp/common/submenu02.jsp" %>			
			<div style="clear: both;">&nbsp;</div>
		</div>
	</div>
</div>

<!-- end #page -->